package org.neuedu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import org.neuedu.common.ResultJson;
import org.neuedu.entity.Department;
import org.neuedu.service.DepartmentService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 科室表 前端控制器
 * </p>
 *
 * @author lzw
 * @since 2024-11-06
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Resource
    DepartmentService departmentService;
    @GetMapping("/list")
    ResultJson<IPage<Department>> list(Integer pageNo, Integer pageSize, String name) throws InterruptedException {
        return ResultJson.success(departmentService.list(pageNo, pageSize, name));
    }
    @PostMapping("/add")
    ResultJson<Boolean> add(String code, String name, String type) {
        return ResultJson.success(departmentService.add(code, name, type), "添加科室成功");
    }

    @PostMapping("/del")
    ResultJson<Boolean> del(Long id,Boolean delmark) {
        System.out.println(id+""+delmark);
        return ResultJson.success(departmentService.del(id, delmark), delmark?"还原科室成功":"删除科室成功");
    }

    @GetMapping("/check")
    ResultJson<Boolean> check(String field,String value,Long id) {
        return ResultJson.success(departmentService.check(field,value,id));
    }
    @GetMapping("/getById")
    ResultJson<Department> getById(Long id) {
        return ResultJson.success(departmentService.getById(id));
    }
    @PostMapping("/update")
    ResultJson<Boolean> update(Long id,String code, String name, String type) {
        return ResultJson.success(departmentService.update(id,code,name,type));
    }
    @GetMapping("/getRegisterDept")
    List<Department> getRegisterDept(){
        return departmentService.getRegisterDept();
    }

}
